package com.tech.connect.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tech.connect.R;

public class MenuTabView extends RelativeLayout {

    private ImageView tab_iv_message;
    private TextView tab_tv_message;
    private View tab_messageDot;
    private TabMenu tabMenu;
    private boolean isSelected;

    public enum TabMenu {
        Home("首页", R.drawable.select_icon_menu_tab_home, R.color.common_select_orange_with_dark, 0),
        Message("消息", R.drawable.select_icon_menu_tab_home_message, R.color.common_select_orange_with_dark, 0),
        Contact("通讯录", R.drawable.select_icon_menu_tab_home_contact, R.color.common_select_orange_with_dark, 0),
        Lighter("发现", R.drawable.select_icon_menu_tab_home_find, R.color.common_select_orange_with_dark, 0),
        User("我的", R.drawable.select_icon_menu_tab_home_user, R.color.common_select_orange_with_dark, 0),

        RenCai_Home("首页", R.drawable.select_icon_menu_tab_rencai_home, R.color.common_select_orange_with_dark, 0),
        RenCai_Message("消息", R.drawable.select_icon_menu_tab_rencai_message, R.color.common_select_orange_with_dark, 0),
        RenCai_Team("建团队", R.drawable.select_icon_menu_tab_rencai_team, R.color.common_select_orange_with_dark, 0),
        RenCai_ZhuanWaiKuai("赚外快", R.drawable.select_icon_menu_tab_rencai_zhuanwaikuai, R.color.common_select_orange_with_dark, 0),
        RenCai_RenMai("人脉", R.drawable.select_icon_menu_tab_rencai_renmai, R.color.common_select_orange_with_dark, 0),


        ZhuanWaiKuai_TouBiaoRen("抢单人", R.drawable.select_icon_menu_tab_zhuanwaikuai_toubiaoren, R.color.common_select_orange_with_dark, 0),
        ZhuanWaiKuai_ZhongBiaoRen("中单人", R.drawable.select_icon_menu_tab_zhuanwaikuai_zhongbiaoren, R.color.common_select_orange_with_dark, 0),
        ZhuanWaiKuai_BaoZhengJin("保证金", R.drawable.select_icon_menu_tab_zhuanwaikuai_baozhengjin, R.color.common_select_orange_with_dark, 0),
        ZhuanWaiKuai_ZiJinTuoGuan("赏金托管", R.drawable.select_icon_menu_tab_zhuanwaikuai_zijintuoguan, R.color.common_select_orange_with_dark, 0),
        ZhuanWaiKuai_ZuJi("足迹", R.drawable.select_icon_menu_tab_zhuanwaikuai_zuji, R.color.common_select_orange_with_dark, 0),

        ZhaoFuWu_Home("首页", R.drawable.select_icon_menu_tab_zhaofuwu_home, R.color.common_select_orange_with_dark, 0),
        ZhaoFuWu_LvYou("旅行", R.drawable.select_icon_menu_tab_zhaofuwu_lvyou, R.color.common_select_orange_with_dark, 0),
        ZhaoFuWu_FuWuZhan("服务站", R.drawable.select_icon_menu_tab_zhaofuwu_fuwuzhan, R.color.common_select_orange_with_dark, 0),
        ZhaoFuWu_QuanZi("圈子", R.drawable.select_icon_menu_tab_zhaofuwu_quanzi, R.color.common_select_orange_with_dark, 0),
        ZhaoFuWu_WoDe("我的", R.drawable.select_icon_menu_tab_zhaofuwu_wode, R.color.common_select_orange_with_dark, 0),


        HuanZheWan_Home("首页", R.drawable.select_icon_menu_tab_huanzhewan_home, R.color.common_select_orange_with_dark, 0),
        HuanZheWan_HuHuanShenFen("互换身份", R.drawable.select_icon_menu_tab_huanzhewan_huhuanshenfen, R.color.common_select_orange_with_dark, 0),
        HuanZheWan_FaShaoYou("发烧友", R.drawable.select_icon_menu_tab_huanzhewan_fashaoyou, R.color.common_select_orange_with_dark, 0),
        HuanZheWan_WanPinGui("玩品柜", R.drawable.select_icon_menu_tab_huanzhewan_wanpingui, R.color.common_select_orange_with_dark, 0);


        public int tvColorResId;
        public int ivResId;
        public String text;
        public int dotNum;

        TabMenu(String text, int ivResId, int tvColorResId, int dotNum) {
            this.tvColorResId = tvColorResId;
            this.ivResId = ivResId;
            this.text = text;
            this.dotNum = dotNum;
        }
    }

    public MenuTabView(Context context) {
        this(context, null);
    }

    public MenuTabView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.view_menu_tab, this, true);
        tab_iv_message = findViewById(R.id.tab_iv_message);
        tab_tv_message = findViewById(R.id.tab_tv_message);
        tab_messageDot = findViewById(R.id.tab_messageDot);
        setTab(tabMenu);
        setSelected(isSelected);
    }

    public void setSelected(boolean isSelected) {
        this.isSelected = isSelected;
        if (tab_iv_message != null) {
            tab_iv_message.setSelected(isSelected);
        }
        if (tab_tv_message != null) {
            tab_tv_message.setSelected(isSelected);
        }
    }

    public void setTab(TabMenu tabMenu) {
        if (tabMenu == null) {
            return;
        }
        this.tabMenu = tabMenu;
        if (tab_iv_message != null) {
            tab_iv_message.setImageResource(tabMenu.ivResId);
        }
        if (tab_tv_message != null) {
            tab_tv_message.setTextColor(getResources().getColorStateList(tabMenu.tvColorResId));
            tab_tv_message.setText(tabMenu.text);
        }
        if (tab_messageDot != null) {
            tab_messageDot.setVisibility(tabMenu.dotNum > 0 ? VISIBLE : GONE);
        }
    }
}
